home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1993 / MacHack 1993.toast / MacHack™ 1987-1992 / MacHack™ '88 / Proceedings '88 / Feldt Advanced Mac Programming / File Manager / List working dirs / wd.c < prev   
Encoding:
C/C++ Source or Header  |  1988-01-04  |  2.0 KB  |  118 lines  |  [TEXT/KAHL]

  1.  
  2. #include <hfs.h>
  3. #include <quickdraw.h>
  4. #include <stdio.h>
  5.  
  6. #ifndef NULL
  7. #define NULL 0L
  8. #endif
  9.  
  10. main()
  11. {
  12. init_mac();
  13. dump_wds();
  14. }
  15.  
  16. dump_wds()
  17. {
  18. WDPBRec            pb;
  19. int                the_vol, count, error, c;
  20. unsigned char     *ptr;
  21. unsigned char     cname[256];
  22.  
  23. pb.ioCompletion = NULL;
  24. pb.ioNamePtr = NULL;
  25. if ( error = PBHGetVol (&pb, FALSE) )
  26.     {
  27.     printf ("\nPBHGetVol error %d", error);
  28.     return;
  29.     }
  30. the_vol = pb.ioWDVRefNum;
  31.  
  32. again:
  33. count = 1;
  34. pb.ioCompletion = NULL;
  35. pb.ioNamePtr = NULL;        /* gives volume name back */
  36. while ( TRUE )
  37.     {
  38.     pb.ioVRefNum = the_vol;
  39.     pb.ioWDVRefNum = the_vol;
  40.     pb.ioWDIndex = count++;
  41.     pb.ioWDProcID = 0 /*'IRWN' */;
  42.     if ( PBGetWDInfo (&pb, FALSE) )
  43.         break;                /* none left */
  44.         
  45.         /* now print them */
  46.     ptr = (unsigned char *)&pb.ioWDProcID;
  47.     printf ("\n wd '%c%c%c%c' %10ld", ptr[0], ptr[1], ptr[2], ptr[3], pb.ioWDDirID);
  48.     get_dir_name(the_vol, pb.ioWDDirID, cname);
  49.     printf (" '%s'", cname);
  50.     }
  51.  
  52. printf("\n\nPress 'z' to do again, other key to exit");
  53. if ( ( c=getchar() ) == 'z' )
  54.     goto again;
  55. }
  56.  
  57. int get_dir_name(vol, dir_id, cname)
  58.     int         vol;
  59.     long        dir_id;
  60.     unsigned char        *cname;
  61. {
  62. CInfoPBRec        cpb;                /* Mac catalog parameter block */
  63. int                error, i;
  64.  
  65. zero_mem ( (char *)&cpb, sizeof(cpb) );
  66.  
  67. cpb.dirInfo.ioFDirIndex = -1;
  68. cpb.dirInfo.ioVRefNum = vol;
  69. cpb.dirInfo.ioDrDirID = dir_id;
  70. cpb.dirInfo.ioNamePtr = cname;
  71.  
  72. error = PBGetCatInfo (&cpb, FALSE);        /* Make File Sys request */
  73.  
  74. if ( error )
  75.     {
  76.     printf ("error %d", error);
  77.     }
  78. else
  79.     PtoCstr(cname);
  80. }
  81.  
  82. /*--------------------------------------
  83.     zero_mem: zeros a block of memory
  84.     
  85.     Passed:
  86.     W         BYTE    *ptr;
  87.     R        UINT    len;
  88.     
  89. --------------------------------------*/
  90.  
  91. zero_mem ( ptr, len )
  92. unsigned char    *ptr;
  93. int    len;
  94. {
  95. while ( len-- )
  96.     *ptr++ = 0;
  97. }
  98.  
  99.  
  100. /*---------------*/
  101. init_mac()
  102. {
  103.  
  104. #ifdef NEEDED
  105. InitGraf (&thePort); 
  106. InitFonts ();
  107. InitWindows();
  108. InitCursor ();
  109. InitMenus ();
  110. InitDialogs (0L);
  111. TEInit();
  112.  
  113. Stdio_MacInit();        /* Tell LightSpeed stdio that we initted toolbox */
  114. FlushEvents(-1, 0);        /* get rid of left over events */
  115. #endif
  116. printf(" ");
  117. }
  118.